package com.edu.controller;

import com.edu.component.PageBean;
import com.edu.component.QueryParam;
import com.edu.service.StudentService;
import com.edu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/Teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @ExceptionHandler(value=Exception.class)
    @ResponseBody
    public String exceptionFallBack(Exception e){
        e.printStackTrace();
        return R.error( e ).toJson();
    }

    /* [1]跳转老师的列表页 */
    @GetMapping("/index")
    public String index(){
        return "views/teacher/teacher_list";
    }

    /* [2]老师列表 JSON [分页查询数据] */
    @GetMapping("/listPage")
    @ResponseBody
    public String listPage(HttpServletRequest req){
        QueryParam param = new QueryParam(req);
        PageBean PB = teacherService.listPage(param);
        return PB.toJson();
    }

}
